#include "Control_StatusBar.h"

#include "RendererComponent.h"

#include "Control_Menu.h"

using namespace gui;

Control_StatusBar::Control_StatusBar(CallbackGetFloatValue NewCallbackGetValue, float NewMin, float NewMax, ColorRGBA<unsigned char> NewDisplayColor, std::string NewCaption, Vec<2, float> NewFontSize, ColorRGBA<unsigned char> NewForeColor, ColorRGBA<unsigned char> NewBackColor, Vec<2, float> NewPos, Vec<2, float> NewSize, Control_Menu* NewParentMenu, Host& NewParentHost) :
Control_Value(NewCallbackGetValue, "%.5f", NewCaption, NewFontSize, NewForeColor, NewBackColor, NewPos, NewSize, NewParentMenu, NewParentHost),
	Min(NewMin),
	Max(NewMax),
	Range(NewMax - NewMin),
	DisplayColor(NewDisplayColor)
{
}

Control_StatusBar::~Control_StatusBar(void)
{
}

void Control_StatusBar::UpdateVerticesFix(RendererComponent& Renderer)
{
	Control_Visible::UpdateVerticesFix(Renderer);
}

void Control_StatusBar::UpdateVerticesSlow(RendererComponent& Renderer)
{
	Control_Value::UpdateVerticesSlow(Renderer);

 	float Lenght = (Size.X * (Value - Min)) / Range;
	float Space = Size.Y * 0.2f;
	
	Renderer.GuiSlowQuadColoredVertices[Renderer.GuiSlowQuadColoredVertexCount++] = VertexPos3Col(
		ParentMenuPos->X + (Pos.X),
		-ParentMenuPos->Y + (-Pos.Y - Space),
		*ParentMenuLayer,
		DisplayColor.R, DisplayColor.G, DisplayColor.B, DisplayColor.A);

	Renderer.GuiSlowQuadColoredVertices[Renderer.GuiSlowQuadColoredVertexCount++] = VertexPos3Col(
		ParentMenuPos->X + (Pos.X),
		-ParentMenuPos->Y + (-Pos.Y - Size.Y + Space),
		*ParentMenuLayer,
		DisplayColor.R, DisplayColor.G, DisplayColor.B, DisplayColor.A);

	Renderer.GuiSlowQuadColoredVertices[Renderer.GuiSlowQuadColoredVertexCount++] = VertexPos3Col(
		ParentMenuPos->X + (Pos.X + Lenght),
		-ParentMenuPos->Y + (-Pos.Y - Size.Y + Space),
		*ParentMenuLayer,
		DisplayColor.R, DisplayColor.G, DisplayColor.B, DisplayColor.A);

	Renderer.GuiSlowQuadColoredVertices[Renderer.GuiSlowQuadColoredVertexCount++] = VertexPos3Col(
		ParentMenuPos->X + (Pos.X + Lenght),
		-ParentMenuPos->Y + (-Pos.Y - Space),
		*ParentMenuLayer,
		DisplayColor.R, DisplayColor.G, DisplayColor.B, DisplayColor.A);
}